import Vue from 'vue';
import Router from 'vue-router';
import { isMobile, isIOS, isAndroid, isWechat } from '@/utils/judgingUA';

// 首页
const Home = () => import('@/views/Home');
// 登录
let Login = () => import('@/views/Login');
// 登录
const MobileLogin = () => import('@/views/Login/mobile');
// 注册
let Register = () => import('@/views/Register');
// 注册
const MobileRegister = () => import('@/views/Register/mobile');
// 忘记密码
let ForgetPwd = () => import('@/views/ForgetPwd');
// 忘记密码
const MobileForgetPwd = () => import('@/views/ForgetPwd/mobile');
// 矿机
const Mill = () => import('@/views/Mill');
// 账户
const SubAccount = () => import('@/views/SubAccount');
// 收益
const Income = () => import('@/views/Income');
// 支付
const PayHistory = () => import('@/views/PayHistory');
// 统计
const Statistics = () => import('@/views/Statistics');
// 邀请
const Invite = () => import('@/views/Invite');
// 邀请图
const Invitation = () => import('@/views/Invitation');
// 用户面板
const Dashboard = () => import('@/views/Dashboard');
// 安全
const SetUp = () => import('@/views/SetUp');
// 验证
const Verifier = () => import('@/views/SetUp/verifier');
// 资产钱包
const Wallet = () => import('@/views/Wallet');
// 我的钱包
const My = () => import('@/views/Wallet/my');
// 账单
const Bill = () => import('@/views/Wallet/bill');
// 提现
const Forward = () => import('@/views/Wallet/forward');
// 钱包列表
const WalletList = () => import('@/views/Wallet/walletList');
// 子账户数
const WalletCount = () => import('@/views/Wallet/walletCount');
// 钱包地址
const WaletAddress = () => import('@/views/Wallet/walletAddress');
// 增加钱包地址
const WaletAdd = () => import('@/views/Wallet/walletAdd');
// 分红
const Dividend = () => import('@/views/Dividend');
// 用户面板一级
const Pools = () => import('@/views/Pools');
// 矿机详情
const MillDetail = () => import('@/views/MillDetail');
// 下载
const Download = () => import('@/views/Download');
// 404
const NotFound = () => import('@/views/404');
// hrt
const Hrt = () => import('@/views/Hrt');
// hrt miningDetail
const HrtMiningDetail = () => import('@/views/Hrt/miningDetail');
// hrt HowGetAddress
const HowGetAddress = () => import('@/views/Hrt/howGetAddress');
// hrt incomeDetail
const IncomeDetail = () => import('@/views/Hrt/incomeDetail');

if (isMobile()) {
  Login = MobileLogin;
  Register = MobileRegister;
  ForgetPwd = MobileForgetPwd;
  document.querySelector('html').setAttribute('data-mobile', true);
  if (isIOS()) {
    document.querySelector('html').setAttribute('data-ios', true);
  } else if (isAndroid()) {
    document.querySelector('html').setAttribute('data-android', true);
  }
  if (isWechat()) {
    document.querySelector('html').setAttribute('data-wechat', true);
  }
}

Vue.use(Router);

/*
 * 命名规则
 * path和name必须是纯小写英文字母，不能有符号
 */

export default new Router({
  mode: 'history',
  fallback: false,
  routes: [{
    path: '/index',
    redirect: '/',
  },
  {
    path: '/home',
    redirect: '/',
  },
  {
    path: '/',
    name: 'index',
    component: Home,
    meta: {
      title: 'router.title',
      observer: false,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta: {
      title: 'header.login',
      observer: false,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/register',
    name: 'register',
    component: Register,
    meta: {
      title: 'header.register',
      observer: false,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/forgetpwd',
    name: 'forgetpwd',
    component: ForgetPwd,
    meta: {
      title: 'login.forget_pwd',
      observer: false,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/statistics',
    name: 'statistics',
    component: Statistics,
    meta: {
      title: 'header.nav.statistics',
      observer: true,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/invite',
    name: 'invite',
    component: Invite,
    meta: {
      title: 'header.nav.invite',
      observer: false,
      freeLogin: false,
      needSubAccount: false,
    },
  },
  {
    path: '/invitation',
    name: 'invitation',
    component: Invitation,
    meta: {
      title: 'header.nav.invite',
      observer: false,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/subaccount',
    name: 'subaccount',
    component: SubAccount,
    meta: {
      title: 'router.account',
      observer: false,
      freeLogin: false,
      needSubAccount: false,
    },
  },
  {
    path: '/setup',
    name: 'setup',
    component: SetUp,
    meta: {
      title: 'router.set',
      observer: false,
      freeLogin: false,
      needSubAccount: false,
    },
  },
  {
    path: '/verifier',
    name: 'verifier',
    component: Verifier,
    meta: {
      title: 'router.verifier',
      observer: false,
      freeLogin: false,
      needSubAccount: true,
    },
  },
  {
    path: '/wallet',
    name: 'wallet',
    redirect: '/wallet/walletlist',
    component: Wallet,
    meta: {
      title: 'router.wallet_walletlist',
      observer: false,
      freeLogin: false,
      needSubAccount: false,
    },
    children: [
      {
        path: 'my',
        component: My,
        meta: {
          title: 'router.wallet_walletlist',
          observer: false,
          freeLogin: false,
          needSubAccount: false,
        },
      },
      {
        path: 'bill',
        component: Bill,
        meta: {
          title: 'router.wallet_walletlist',
          observer: false,
          freeLogin: false,
          needSubAccount: false,
        },
      },
      {
        path: 'walletlist',
        component: WalletList,
        meta: {
          title: 'router.wallet_walletlist',
          observer: false,
          freeLogin: false,
          needSubAccount: false,
        },
      },
      {
        path: 'walletcount',
        component: WalletCount,
        meta: {
          title: 'router.wallet_walletlist',
          observer: false,
          freeLogin: false,
          needSubAccount: false,
        },
      },
      {
        path: 'forward',
        component: Forward,
        meta: {
          title: 'router.wallet_walletlist',
          observer: false,
          freeLogin: false,
          needSubAccount: false,
        },
      },
      {
        path: 'address',
        component: WaletAddress,
        meta: {
          title: 'router.wallet_address',
          observer: false,
          freeLogin: false,
          needSubAccount: false,
        },
      },
      {
        path: 'add',
        component: WaletAdd,
        meta: {
          title: 'router.add_wallet_address',
          observer: false,
          freeLogin: false,
          needSubAccount: false,
        },
      },
    ],
  },
  {
    path: '/download',
    name: 'download',
    component: Download,
    meta: {
      title: 'download.1',
      observer: true,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/dividend',
    name: 'dividend',
    component: Dividend,
    meta: {
      title: 'router.dividend',
      observer: false,
      freeLogin: false,
      needSubAccount: false,
    },
  },
  {
    path: '/pools',
    name: 'pools',
    redirect: 'pools/dashboard',
    component: Pools,
    meta: {
      title: 'router.dashboard',
      observer: true,
      freeLogin: false,
      needSubAccount: true,
    },
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: Dashboard,
        meta: {
          title: 'router.dashboard',
          observer: true,
          freeLogin: false,
          needSubAccount: true,
        },
      },
      {
        path: 'mill',
        name: 'mill',
        component: Mill,
        meta: {
          title: 'router.mill',
          observer: true,
          freeLogin: false,
          needSubAccount: true,
        },
      },
      {
        path: 'mill/:id',
        name: 'milldetail',
        component: MillDetail,
        meta: {
          title: 'router.milldetail',
          observer: true,
          freeLogin: false,
          needSubAccount: true,
        },
      },
      {
        path: 'payhistory',
        name: 'payhistory',
        component: PayHistory,
        meta: {
          title: 'router.payhistory',
          observer: true,
          freeLogin: false,
          needSubAccount: true,
        },
      },
      {
        path: 'income',
        name: 'income',
        component: Income,
        meta: {
          title: 'router.income',
          observer: true,
          freeLogin: false,
          needSubAccount: true,
        },
      },
    ],
  },
  {
    path: '/hrt',
    redirect: '/hrt/home',
  },
  {
    path: '/hrt/home',
    name: 'hrt',
    component: Hrt,
    meta: {
      title: 'router.hrt',
      observer: false,
      freeLogin: true,
      needSubAccount: true,
    },
  },
  {
    path: '/hrt/miningdetail',
    name: 'HrtMiningDetail',
    component: HrtMiningDetail,
    meta: {
      title: 'router.hrtMiningDetail',
      observer: false,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/hrt/howgetaddress',
    name: 'HowGetAddress',
    component: HowGetAddress,
    meta: {
      title: 'router.howGetAddress',
      observer: false,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '/hrt/incomedetail',
    name: 'IncomeDetail',
    component: IncomeDetail,
    meta: {
      title: 'router.incomeDetail',
      observer: false,
      freeLogin: false,
      needSubAccount: true,
    },
  },
  {
    path: '/404',
    name: '404',
    component: NotFound,
    meta: {
      title: '404',
      observer: true,
      freeLogin: true,
      needSubAccount: false,
    },
  },
  {
    path: '*',
    redirect: '/404',
  }],
  scrollBehavior() {
    return { x: 0, y: 0 };
  },
});
